package com.emm.yixun.mobile.fragment;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.emm.yixun.mobile.R;
import com.emm.yixun.mobile.adapter.CustomerAdapter;
import com.emm.yixun.mobile.adapter.ScreenONEAdapter;
import com.emm.yixun.mobile.adapter.ScreenTWOAdapter;
import com.emm.yixun.mobile.application.EmmApplication;
import com.emm.yixun.mobile.base.BaseActivity;
import com.emm.yixun.mobile.model.DistributionConsultant;
import com.emm.yixun.mobile.model.GetConsultantList;
import com.emm.yixun.mobile.model.GetConsultantList.ConsultantList;
import com.emm.yixun.mobile.model.GetCustomerList;
import com.emm.yixun.mobile.model.GetCustomerList.CustomerList;
import com.emm.yixun.mobile.model.GetDictionaryList;
import com.emm.yixun.mobile.model.GetDictionaryList.RqBusNumList;
import com.emm.yixun.mobile.model.ScreenOneModel;
import com.emm.yixun.mobile.model.ScreenOneModel.Info;
import com.emm.yixun.mobile.ui.FirstContactActivity;
import com.emm.yixun.mobile.ui.customer.FollowUpActivity;
import com.emm.yixun.mobile.ui.customer.SearchCustomerActivity;
import com.emm.yixun.mobile.ui.web.WebActivity;
import com.emm.yixun.utils.ToastUtils;
import com.eroad.product.tools.PickerView;
import com.eroad.product.tools.PickerView.onSelectListener;
import com.eroad.product.tools.PopuContent;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.swu.pulltorefresh.PullToRefreshSwipeMenuListView;
import cn.swu.pulltorefresh.PullToRefreshSwipeMenuListView.IXListViewListener;
import cn.swu.pulltorefresh.PullToRefreshSwipeMenuListView.OnMenuItemClickListener;
import cn.swu.swipemenulistview.SwipeMenu;
import cn.swu.swipemenulistview.SwipeMenuCreator;
import cn.swu.swipemenulistview.SwipeMenuItem;
import xf.tointinataface.FlyprintInataface;
import xf.tools.Loading;

/**
 * 客户
 */
public class CustomerFragment extends Fragment implements IXListViewListener {

    private static final String TAG = "CustomerFragment";
    public static final String IS_SELECT = "IS_SELECT";
    public static final String CUSTOMER = "CUSTOMER";

    private boolean isSelect = false;

    /**
     * 被分配对象
     */
    ArrayList<CustomerListinfo> customerList = new ArrayList<>();

    /**
     * 0群发短信 1批量指派
     */
    private int sureType = 0;

    FragmentActivity root;

    /**
     * 刷新侧滑菜单listview
     */
    PullToRefreshSwipeMenuListView swipeList;

    /**
     * 适配器
     */
    CustomerAdapter adapter;

    /**
     * 排序，筛选菜单箭头
     */
    ImageView icon1, icon2;

    /**
     * 排序
     */
    LinearLayout tvSort;

    /**
     * 排序,筛选
     */
    TextView colors_text, colors_text2;

    /**
     * 筛选
     */
    LinearLayout tvScreen;

    /**
     * 菜单
     */
    PopupWindow morePoPu;

    /**
     * 菜单
     */
    View view;

    /**
     * 排序
     */
    View viewSort;

    /**
     * 排序
     */
    PopupWindow poPuSort;

    /**
     * 筛选
     */
    View viewScreen;

    /**
     * 筛选
     */
    PopupWindow poPuScreen;

    /**
     * 指派
     */
    View viewZp;

    /**
     * 指派
     */
    PopupWindow poPuZp;

    /**
     * 指派选择框选中的置业顾问
     */
    private String selectName;

    /**
     * 指派选择框选中的置业顾问的下标
     */
    private int SelectID;

    /**
     * 标题
     */
    TextView title_main;

    /**
     * 筛选模块
     */
    LinearLayout select_fs, llSearch;

    /**
     * 是否是批量选择状态 true不是 false 是
     */
    public boolean select_bl = true;


    /**
     * 排序选择标识
     */
    private int setSelect = 1;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Bundle bundle = getArguments();
        if (bundle != null) isSelect = bundle.getBoolean(IS_SELECT, false);
        return inflater.inflate(R.layout.customer_frg, null);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        root = getActivity();

        if (EmmApplication.isTips()) {
            setSelect = 1;
        }

        initView();
        initBtn();

        Loading.showDialogForLoading(root, "正在加载...", false, true, 60000);

        // 查询客户列表接口
        getCustomerList("" + setSelect, "", "", "" + pageNumber, "" + pageSize, 1);
        // 查询置业顾问列表接口
        getConsultantList();
        // 查询字典列表接口
        getDictionaryList();
    }

    /**
     * <p>
     * <b>Title：</b> 刷新
     * </p>
     * <p>
     * <b>Description：</b> 刷新前需要对之前数据清空，避免请求失败出现滞留数据
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 上午10:39:29
     */
    public void Reload() {

        getConsultantList();// 重新获取数据

        if (adapter == null) {// 是否已存在，降低计算成本
            adapter = new CustomerAdapter(root, null);
            swipeList.setAdapter(adapter);
        } else {
            adapter.SetDate(null);
        }

        getcustomer = new GetCustomerList();

        Log.v(TAG, "清空list");

        Loading.showDialogForLoading(root, "正在加载...", false, true, 60000);

        // 重新获取数据
        pageNumber = 1;
        getCustomerList("" + setSelect, itemid1, itemid2, "" + 1, "" + pageSize, 1);

        getDictionaryList();
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        if (hidden) {
            Log.v(TAG, "Fragment的onPause");
        } else {
            Log.v(TAG, "Fragment的onResume");
            // 相当于Fragment的onResume
            if (select_bl)
                onresumevoid();
        }
    }

    /**
     * <p>
     * <b>Title：</b> 是否刷新
     * </p>
     * <p>
     * <b>Description：</b>（根据其他界面所操作相关修改，判断是否需要刷新）
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 上午10:40:16
     */
    public void onresumevoid() {
        // if (EmmApplication.IS_RELOAD) {// 客户列表是否刷新
        // EmmApplication.IS_RELOAD = false;

        if (adapter == null) {
            adapter = new CustomerAdapter(root, null);
            swipeList.setAdapter(adapter);
        } else {
            adapter.SetDate(null);
        }

        if (null == getcustomer) {// 为空不处理，不为空就重新初始化
        } else {
            getcustomer = new GetCustomerList();
        }

        Log.v(TAG, "清空list->");
        Loading.showDialogForLoading(root, "正在加载...", false, true, 60000);
        pageNumber = 1;
        getCustomerList("" + setSelect, itemid1, itemid2, "" + 1, "" + pageSize, 1);
        // } else {
        // if (adapter != null) {
        // adapter.notifyDataSetChanged();
        // }
        // }
    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    /**
     * <p>
     * <b>Title：</b> 初始化view
     * </p>
     * <p>
     * <b>Description：</b> 实例化view，绑定ID
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 上午10:41:17
     */
    private void initView() {
        llSearch = (LinearLayout) root.findViewById(R.id.ll_search);
        tvSort = (LinearLayout) root.findViewById(R.id.sort_textview);
        colors_text = (TextView) root.findViewById(R.id.colors_text);
        colors_text2 = (TextView) root.findViewById(R.id.colors_text2);
        icon1 = (ImageView) root.findViewById(R.id.icon1);
        icon2 = (ImageView) root.findViewById(R.id.icon2);
        tvScreen = (LinearLayout) root.findViewById(R.id.screen_textview);
        swipeList = (PullToRefreshSwipeMenuListView) root.findViewById(R.id.listView);
        select_fs = (LinearLayout) root.findViewById(R.id.select_fs);
        LinearLayout header = (LinearLayout) root.findViewById(R.id.customer_include);
        if (isSelect) {
            header.setVisibility(View.GONE);
        } else {
            RelativeLayout main_head_top_rela = (RelativeLayout) header.findViewById(R.id.main_head_top_rela);
            BaseActivity.SetViewHeight(main_head_top_rela);// 更改relativelayout的高度
        }

        // 配置下拉刷新列表属性
        swipeList.setPullRefreshEnable(true);
        swipeList.setPullLoadEnable(true);
        swipeList.setXListViewListener(this);
        swipeList.setRefreshTime(EmmApplication.getData("RefreshTime"));

        try {
            // 客户菜单权限下按钮权限：客户分配 String(1) 客户分配：0无 1 有
            if ("1".equals(EmmApplication.getData(EmmApplication.isDistributionCustomer))) {
                initMenuListView(1);// 配置listview的item侧滑菜单
            } else {
                initMenuListView(2);
            }
        } catch (NullPointerException e) {
            e.printStackTrace();
        }
    }

    /**
     * <p>
     * <b>Title：</b> 事件监听
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 上午10:41:48
     */
    private void initBtn() {

        llSearch.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                searchset();
            }
        });

        // 排序
        tvSort.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                colors_text.setTextColor(Color.parseColor("#FD593E"));
                colors_text2.setTextColor(Color.parseColor("#3E3C3D"));
                icon1.setImageResource(R.drawable.paixu_down);
                icon2.setImageResource(R.drawable.shaixuan_up);
                setSortPoPu();// 排序菜单
            }
        });

        // 筛选
        tvScreen.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                colors_text.setTextColor(Color.parseColor("#3E3C3D"));
                colors_text2.setTextColor(Color.parseColor("#FD593E"));
                icon1.setImageResource(R.drawable.paixu_up);
                icon2.setImageResource(R.drawable.shaixuan_down);
                Setscreen_create();// 筛选菜单
            }
        });

        // 客户列表
        swipeList.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.w(TAG, "a--" + position);
                if (isSelect) {
                    CustomerList customer = getcustomer.getCustomerList().get(position - 1);
                    Intent intent = new Intent();
                    intent.putExtra(CUSTOMER, customer);
                    getActivity().setResult(Activity.RESULT_OK, intent);
                    getActivity().finish();
                } else {
                    if (position == 0) {// 不处理
                    } else {// 否则减去头部占用的一个位置
                        position--;
                        if (select_bl) {
                            if ("1".equals(getcustomer.getCustomerList().get(position).getDataAuthority())) {
                                final String customerId = getcustomer.getCustomerList().get(position).getCustomerId();
                                WebActivity.Companion.jump2CustomerDetail(getActivity(), customerId);
                            } else {
                                ToastUtils.INSTANCE.showToast("无权限查看当前客户详情");
                            }
                        } else {
                            adapter.select(position);
                        }
                    }
                }
                Log.w(TAG, "b--" + position);
            }
        });
    }

    /**
     * <p>
     * <b>Title：</b> 全选或者取消
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param isselect
     * @author tangxin
     * @date 2017年2月20日 下午5:58:46
     */
    public void SelectOrCancelAll(boolean isselect) {
        if (null != adapter) {
            adapter.SelectAll(isselect);
            // 校验是否全选，并获取选中条数
            FlyprintInataface.select(adapter.IsSelect());
            FlyprintInataface.size(adapter.getSize());
        } else {
            PopuContent.poPu(root, "当前没有客户", false, 0);
        }
    }

    /**
     * <p>
     * <b>Title：</b> 发起短信或批量分配方法
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 上午10:42:04
     */
    public void shure() {

        List<String> tel = new ArrayList<String>();

        customerList.clear();// 数据清空，避免新数据加入造成重复

        if (getcustomer != null && getcustomer.getCustomerList() != null) {// 非空校验
            for (int o = 0; o < getcustomer.getCustomerList().size(); o++) {// 数据循环转存
                if (getcustomer.getCustomerList().get(o).isIsselect()) {
                    tel.add(getcustomer.getCustomerList().get(o).getMobile());
                    CustomerListinfo c = new CustomerListinfo();
                    c.setCustomerId(getcustomer.getCustomerList().get(o).getCustomerId());
                    customerList.add(c);
                }
            }
        } else {// 不存在提出提示
            PopuContent.poPu(root, "当前没有客户", false, 0);
            select_fs.setVisibility(View.VISIBLE);
            select_bl = true;
            return;
        }

        if (tel.size() < 1) {// 校验下步操作的可实行性
            PopuContent.poPu(root, "还未选择客户", false, 0);
            adapter.GetIsv(false);
            adapter.notifyDataSetChanged();
            select_fs.setVisibility(View.VISIBLE);
            select_bl = true;
        } else {
            disselect();// 取消选择模式
            if (sureType == 0) {// 短信
                EmmApplication.sendMMS(tel);
            } else if (sureType == 1) {// 指派
                // 校验指派对象的存在性
                if (getconsultan != null && getconsultan.getConsultantList() != null) {
                    if (getconsultan.getConsultantList().size() > 0) {
                        SetzpPopu(getconsultan.getConsultantList());
                    } else {
                        PopuContent.poPu(root, "当前没有置业顾问", false, 0);
                    }
                } else {
                    PopuContent.poPu(root, "当前没有置业顾问", false, 0);
                }
            }
        }
    }

    /**
     * <p>
     * <b>Title：</b> 取消选择模式
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 上午10:42:39
     */
    public void disselect() {

        if (adapter != null) {
            adapter.GetIsv(false);// 更改列表item的展示模式

            if (null != getcustomer) {
                try {
                    for (int o = 0; o < getcustomer.getCustomerList().size(); o++) {
                        if (getcustomer.getCustomerList().get(o).isIsselect()) {
                            getcustomer.getCustomerList().get(o).setIsselect(false);
                        }
                    }
                } catch (NullPointerException e) {
                    Log.v(TAG, "getcustomer   null ");
                }
            }

            // 刷新
            adapter.notifyDataSetChanged();
            select_fs.setVisibility(View.VISIBLE);
            select_bl = true;
        }
    }

    /**
     * <p>
     * <b>Title：</b> 配置listview的item侧滑菜单
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param type 1 有权限 2无权限
     * @author tangxin
     * @date 2016年12月7日 上午10:44:20
     */
    private void initMenuListView(final int type) {
        SwipeMenuCreator creator = new SwipeMenuCreator() {
            @Override
            public void create(SwipeMenu menu) {

                // 配置侧滑菜单按钮

                SwipeMenuItem openItem = new SwipeMenuItem(root);
                openItem.setBackground(new ColorDrawable(Color.parseColor("#F82B49")));
                openItem.setWidth(dp2px(70));
                openItem.setTitle("打电话");
                openItem.setTitleSize(14);
                openItem.setTitleColor(Color.WHITE);
                menu.addMenuItem(openItem);

                SwipeMenuItem openItem2 = new SwipeMenuItem(root);
                openItem2.setBackground(new ColorDrawable(Color.parseColor("#FF6253")));
                openItem2.setWidth(dp2px(70));
                openItem2.setTitle("首触");
                openItem2.setTitleSize(14);
                openItem2.setTitleColor(Color.WHITE);
                menu.addMenuItem(openItem2);

                SwipeMenuItem openItem3 = new SwipeMenuItem(root);
                openItem3.setBackground(new ColorDrawable(Color.parseColor("#FF7200")));
                openItem3.setWidth(dp2px(70));
                openItem3.setTitle("写跟进");
                openItem3.setTitleSize(14);
                openItem3.setTitleColor(Color.WHITE);
                menu.addMenuItem(openItem3);

                if (type == 1) {// 根据权限选择是否配置
                    SwipeMenuItem openItem4 = new SwipeMenuItem(root);
                    openItem4.setBackground(new ColorDrawable(Color.parseColor("#ffb527")));
                    openItem4.setWidth(dp2px(70));
                    openItem4.setTitle("分配");
                    openItem4.setTitleSize(14);
                    openItem4.setTitleColor(Color.WHITE);
                    menu.addMenuItem(openItem4);
                }
            }
        };
        swipeList.setMenuCreator(creator);
        // 侧滑菜单的相应事件
        swipeList.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            @Override
            public void onMenuItemClick(int position, SwipeMenu menu, int index) {
                boolean hasPermission = "1".equals(getcustomer.getCustomerList().get(position).getDataAuthority());
                if (hasPermission) {
                    switch (index) {
                        case 0:// 第一个添加的菜单的响应事件
                            Log.w("侧滑菜单的相应事件1", "被点击");
                            EmmApplication.callPhone(getcustomer.getCustomerList().get(position).getMobile(), getcustomer
                                    .getCustomerList().get(position).getCustomerId());
                            break;
                        case 1:// 第二个添加的菜单的响应事件
                            Log.w("侧滑菜单的相应事件2", "被点击");
//                        List<String> l = new ArrayList<String>();
//                        l.add(getcustomer.getCustomerList().get(position).getMobile());
//                        EmmApplication.sendMMS(l);
                            Intent second = new Intent(getContext(), FirstContactActivity.class);
                            second.putExtra(FirstContactActivity.CUSTOMER, getcustomer.getCustomerList().get(position));
                            startActivity(second);
                            break;
                        case 2:// 第三个添加的菜单的响应事件
                            Log.w("侧滑菜单的相应事件3", "被点击" + position);
                            Intent intent = new Intent(root, FollowUpActivity.class);
                            intent.putExtra("customerId", getcustomer.getCustomerList().get(position).getCustomerId());
                            intent.putExtra("SEX", getcustomer.getCustomerList().get(position).getCustomerSex());
                            intent.putExtra("NUMBER", getcustomer.getCustomerList().get(position).getIntentionLevel());
                            intent.putExtra("CUSTOMERSTATUS", getcustomer.getCustomerList().get(position).getCustomerStatus());
                            intent.putExtra("CUSTOMERORIGIN", getcustomer.getCustomerList().get(position).getCustomerOrigin());
                            intent.putExtra("STAR", getcustomer.getCustomerList().get(position).getStar());
                            intent.putExtra("NAME", getcustomer.getCustomerList().get(position).getCustomerName());
                            intent.putExtra("TEL", getcustomer.getCustomerList().get(position).getMobile());
                            startActivity(intent);
                            break;
                        case 3:// 第三个添加的菜单的响应事件
                            Log.w("侧滑菜单的相应事件4", "被点击");
                            customerList.clear();
                            CustomerListinfo object = new CustomerListinfo();
                            object.setCustomerId(getcustomer.getCustomerList().get(position).getCustomerId());
                            customerList.add(object);

                            if (getconsultan != null && getconsultan.getConsultantList() != null) {
                                if (getconsultan.getConsultantList().size() > 0) {
                                    SetzpPopu(getconsultan.getConsultantList());
                                } else {
                                    PopuContent.poPu(root, "当前没有置业顾问", false, 0);
                                }
                            } else {
                                PopuContent.poPu(root, "当前没有置业顾问", false, 0);
                            }

                            break;
                        default:
                            break;
                    }
                } else {
                    ToastUtils.INSTANCE.showToast("您没有操作权限");
                }
            }
        });
    }

    // 将dp转化为px
    private int dp2px(int dp) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics());
    }

    /**
     * 刷新
     */
    @Override
    public void onRefresh() {
        Log.v("loadListener", "refresh");
        swipeList.stopLoadMore();// 关闭加载更多动画
        swipeList.setPullLoadEnable(true);
        h.sendEmptyMessage(1);
    }

    /**
     * 加载更多
     */
    @Override
    public void onLoadMore() {
        Log.v("loadListener", "loadMore");
        swipeList.stopRefresh();// 关闭刷新动画
        h.sendEmptyMessage(2);
    }

    /**
     * 模拟加载效果
     */
    @SuppressLint("HandlerLeak")
    Handler h = new Handler() {
        public void handleMessage(android.os.Message msg) {
            if (msg.what == 1) {// 刷新
                pageNumber = 1;
                getCustomerList("" + setSelect, itemid1, itemid2, "" + 1, "" + pageSize, 1);
            } else if (msg.what == 2) {// 加载更多
                pageNumber++;
                getCustomerList("" + setSelect, itemid1, itemid2, "" + pageNumber, "" + pageSize, 2);
            }
        }

        ;
    };

    /**
     * <p>
     * <b>Title：</b> 跳转到搜索界面
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月21日 下午3:03:26
     */
    public void searchset() {
        Intent intent = new Intent();
        intent.putExtra("TYPE", "" + 1);
        intent.setClass(root, SearchCustomerActivity.class);
        startActivity(intent);
    }

    /**
     * <p>
     * <b>Title：</b> 跳转新增(修改)用户界面
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月21日 下午3:03:39
     */
    public void newcustomerset() {
        WebActivity.Companion.jump2AddCustomer(getActivity());
    }

    /**
     * <p>
     * <b>Title：</b> 发送短信之后界面恢复
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月21日 下午3:03:59
     */
    public void smsset() {
        sureType = 0;
        if (null != adapter) {
            adapter.GetIsv(true);
            adapter.notifyDataSetChanged();
            select_fs.setVisibility(View.GONE);
            select_bl = false;
        } else {
            EmmApplication.T("当前没有客户");
        }

    }

    /**
     * <p>
     * <b>Title：</b> 批量选择确认或取消之后的界面恢复
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月21日 下午3:04:28
     */
    public void allotset() {
        if (null != adapter) {
            sureType = 1;
            adapter.GetIsv(true);
            adapter.notifyDataSetChanged();
            select_fs.setVisibility(View.GONE);
            select_bl = false;
        } else {
            Log.v(TAG, "客户为空");
        }
    }

    /**
     * <p>
     * <b>Title：</b> 排序菜单
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月21日 下午3:04:57
     */
    public void setSortPoPu() {
        viewSort = LayoutInflater.from(root).inflate(R.layout.popu_sort, null);
        poPuSort = new PopupWindow(viewSort, android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT,
                android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT);
        poPuSort.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        poPuSort.showAtLocation(tvSort, Gravity.TOP, 0, 0);
        poPuSort.setFocusable(true);
        poPuSort.setOutsideTouchable(true);
        viewSort.setFocusable(true);
        viewSort.setFocusableInTouchMode(true);

        viewSort.setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    poPuSort.dismiss();
                    EmmApplication.setLog(root);
                }
                return false;
            }
        });

        viewSort.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                poPuSort.dismiss();
                EmmApplication.setLog(root);
            }
        });

        // 最新创建
        TextView newCreate = (TextView) viewSort.findViewById(R.id.new_creaete);
        // 最新更新
        TextView newUpdate = (TextView) viewSort.findViewById(R.id.new_update);
        // 最新跟进
        TextView newFgo = (TextView) viewSort.findViewById(R.id.new_fgo);
        // 按标星
        TextView numberStar = (TextView) viewSort.findViewById(R.id.number_star);
        // 按客户等级
        TextView tvCustomerLevel = (TextView) viewSort.findViewById(R.id.tv_customer_level);

        if (EmmApplication.isTips()) {
            newCreate.setText("最新创建(默认)");
        }

        ImageView g1 = (ImageView) viewSort.findViewById(R.id.g1);
        ImageView g2 = (ImageView) viewSort.findViewById(R.id.g2);
        ImageView g3 = (ImageView) viewSort.findViewById(R.id.g3);
        ImageView g4 = (ImageView) viewSort.findViewById(R.id.g4);
        ImageView g5 = (ImageView) viewSort.findViewById(R.id.g5);

        // 选中的item展示勾选
        g1.setVisibility(setSelect == 1 ? View.VISIBLE : View.INVISIBLE);
        g2.setVisibility(setSelect == 2 ? View.VISIBLE : View.INVISIBLE);
        g3.setVisibility(setSelect == 3 ? View.VISIBLE : View.INVISIBLE);
        g4.setVisibility(setSelect == 4 ? View.VISIBLE : View.INVISIBLE);
        g5.setVisibility(setSelect == 5 ? View.VISIBLE : View.INVISIBLE);

        // 选中的item颜色特例显示
        newCreate.setTextColor(setSelect == 1 ? Color.parseColor("#f87242") : Color.parseColor("#494949"));
        newUpdate.setTextColor(setSelect == 2 ? Color.parseColor("#f87242") : Color.parseColor("#494949"));
        newFgo.setTextColor(setSelect == 3 ? Color.parseColor("#f87242") : Color.parseColor("#494949"));
        numberStar.setTextColor(setSelect == 4 ? Color.parseColor("#f87242") : Color.parseColor("#494949"));
        tvCustomerLevel.setTextColor(setSelect == 5 ? Color.parseColor("#f87242") : Color.parseColor("#494949"));

        // 最新创建
        newCreate.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                poPuSort.dismiss();
                EmmApplication.setLog(root);
                setSelect = 1;
                pageNumber = 1;
                Loading.showDialogForLoading(root, "正在加载...", false, true, 60000);
                getCustomerList();
            }
        });

        // 最新
        newUpdate.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                poPuSort.dismiss();
                EmmApplication.setLog(root);
                setSelect = 2;
                pageNumber = 1;
                Loading.showDialogForLoading(root, "正在加载...", false, true, 60000);
                getCustomerList();
            }
        });

        // 最新跟进
        newFgo.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                poPuSort.dismiss();
                EmmApplication.setLog(root);
                setSelect = 3;
                pageNumber = 1;
                Loading.showDialogForLoading(root, "正在加载...", false, true, 60000);
                getCustomerList();
            }
        });

        // 星标排序
        numberStar.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                poPuSort.dismiss();
                EmmApplication.setLog(root);
                setSelect = 4;
                pageNumber = 1;
                Loading.showDialogForLoading(root, "正在加载...", false, true, 60000);
                getCustomerList();
            }
        });

        // 最新创建
        tvCustomerLevel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                poPuSort.dismiss();
                EmmApplication.setLog(root);
                setSelect = 5;
                pageNumber = 1;
                Loading.showDialogForLoading(root, "正在加载...", false, true, 60000);
                getCustomerList();
            }
        });
    }

    private void getCustomerList() {
        getCustomerList("" + setSelect, itemid1, itemid2, "" + pageNumber, "" + pageSize, 1);
    }

    /**
     * 主 筛选
     */
    private int select_id = 0;

    /**
     * 次 筛选
     */
    private int select_id2 = 0;

    /**
     * 筛选主菜单ID
     */
    String itemid1 = "1";

    /**
     * 筛选子菜单ID
     */
    String itemid2;

    /**
     * <p>
     * <b>Title：</b> 筛选
     * </p>
     * <p>
     * <b>Description：</b> 每项筛选类型添加一项 全部，重构方法
     * </p>
     *
     * @author tangxin
     * @date 2016年12月29日 上午10:55:17
     */
    public void Setscreen_create() {
        viewScreen = LayoutInflater.from(root).inflate(R.layout.popu_screen, null);
        poPuScreen = new PopupWindow(viewScreen, android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT,
                android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT);
        poPuScreen.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        poPuScreen.showAtLocation(tvSort, Gravity.TOP, 0, 0);
        poPuScreen.setFocusable(true);
        poPuScreen.setOutsideTouchable(true);
        viewScreen.setFocusable(true);
        viewScreen.setFocusableInTouchMode(true);

        viewScreen.setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    poPuScreen.dismiss();
                    EmmApplication.setLog(root);
                }
                return false;
            }
        });

        viewScreen.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                poPuScreen.dismiss();
                EmmApplication.setLog(root);
            }
        });

        ListView screen_listview1 = (ListView) viewScreen.findViewById(R.id.screen_listview1);
        ListView screen_listview2 = (ListView) viewScreen.findViewById(R.id.screen_listview2);

        final List<ScreenOneModel> listm = new ArrayList<ScreenOneModel>();

        // 初始化展示数据
        for (int i = 0; i < 5; i++) {
            ScreenOneModel sd = new ScreenOneModel();
            List<Info> listc = new ArrayList<Info>();
            if (i == 0) {
                sd.setName1("客户状态");
                sd.setNameid1("1");

                Info n0 = new Info();
                n0.setName2("全部");
                n0.setNameid("0");
                listc.add(n0);

                Info n = new Info();
                n.setName2("问询");
                n.setNameid("1");
                listc.add(n);

                Info n1 = new Info();
                n1.setName2("来访");
                n1.setNameid("2");
                listc.add(n1);

                if ("1".equals(EmmApplication.getData(EmmApplication.FROMDETAILSTYPE))) {// 拥有认筹权限
                    Info n2 = new Info();
                    n2.setName2("认筹");
                    n2.setNameid("3");
                    listc.add(n2);
                }

                Info n4 = new Info();
                n4.setName2("认购");
                n4.setNameid("4");
                listc.add(n4);

                Info n6 = new Info();
                n6.setName2("签约");
                n6.setNameid("5");
                listc.add(n6);

                Info n7 = new Info();
                n7.setName2("无意向");
                n7.setNameid("6");
                listc.add(n7);

                sd.setInfo(listc);
                listm.add(sd);
            } else if (i == 1) {
                sd.setName1("意向等级");
                sd.setNameid1("2");

                Info n0 = new Info();
                n0.setName2("全部");
                n0.setNameid("0");
                listc.add(n0);

                Info n1 = new Info();
                n1.setName2("A");
                n1.setNameid("2");
                listc.add(n1);

                Info n2 = new Info();
                n2.setName2("B");
                n2.setNameid("3");
                listc.add(n2);

                Info n3 = new Info();
                n3.setName2("C");
                n3.setNameid("4");
                listc.add(n3);

                Info n4 = new Info();
                n4.setName2("D");
                n4.setNameid("5");
                listc.add(n4);
                sd.setInfo(listc);
                listm.add(sd);
            } else if (i == 2) {
                sd.setName1("跟进时间");
                sd.setNameid1("3");

                Info n0 = new Info();
                n0.setName2("全部");
                n0.setNameid("0");
                listc.add(n0);

                Info n = new Info();
                n.setName2("3天未跟进");
                n.setNameid("1");
                listc.add(n);

                Info n1 = new Info();
                n1.setName2("一周未跟进");
                n1.setNameid("2");
                listc.add(n1);

                Info n2 = new Info();
                n2.setName2("两周未跟进");
                n2.setNameid("3");
                listc.add(n2);

                Info n3 = new Info();
                n3.setName2("一月未跟进");
                n3.setNameid("4");
                listc.add(n3);

                Info n4 = new Info();
                n4.setName2("两月未跟进");
                n4.setNameid("5");
                listc.add(n4);
                sd.setInfo(listc);
                listm.add(sd);
            } else if (i == 3) {
                sd.setName1("首次接触方式");
                sd.setNameid1("4");

                Info n0 = new Info();
                n0.setName2("全部");
                n0.setNameid("0");
                listc.add(n0);

                if (FirstContactMode != null && FirstContactMode.size() > 0) {
                    for (int y = 0; y < FirstContactMode.size(); y++) {
                        Info n = new Info();
                        n.setName2(FirstContactMode.get(y).getDictionaryName());
                        n.setNameid(FirstContactMode.get(y).getDictionaryId());
                        listc.add(n);
                    }
                    sd.setInfo(listc);
                } else {
                }

                listm.add(sd);
            } else if (i == 4) {
                sd.setName1("归属人");
                sd.setNameid1("5");

                Info n0 = new Info();
                n0.setName2("全部");
                n0.setNameid("0");
                listc.add(n0);

                if (getconsultan != null && getconsultan.getConsultantList() != null) {
                    if (getconsultan.getConsultantList().size() > 0) {
                        for (int n = 0; n < getconsultan.getConsultantList().size(); n++) {
                            Info info = new Info();
                            info.setName2(getconsultan.getConsultantList().get(n).getConsultantUserName());
                            info.setNameid(getconsultan.getConsultantList().get(n).getConsultantUserId());
                            listc.add(info);
                        }
                        sd.setInfo(listc);
                    } else {
                    }
                } else {
                }
                listm.add(sd);
            }
        }

        final ScreenONEAdapter adapter = new ScreenONEAdapter(root, listm);
        final ScreenTWOAdapter adapter2 = new ScreenTWOAdapter(root, listm.get(select_id).getInfo());

        // 绑定适配器
        screen_listview1.setAdapter(adapter);
        screen_listview2.setAdapter(adapter2);

        // 默认选择一项
        screen_listview1.setSelection(select_id);
        adapter.SetSelect(select_id);
        adapter2.SetSelect(select_id2);
        screen_listview2.setSelection(select_id2);

        // 主筛选列表监听
        screen_listview1.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                adapter2.getDate(listm.get(arg2).getInfo(), select_id2);
                select_id = arg2;
                select_id2 = 0;

                itemid1 = listm.get(arg2).getNameid1();

                // 刷新主筛选列表的展示界面
                adapter.SetSelect(select_id);
                // 刷新次级筛选列表数据，以当前主筛选列表选中项为主键
                adapter2.SetSelect(select_id2);

            }
        });

        // 次级筛选列表监听
        screen_listview2.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                poPuScreen.dismiss();
                EmmApplication.setLog(root);
                select_id2 = arg2;

                // 刷新次级筛选列表的展示界面
                adapter2.SetSelect(select_id2);

                itemid2 = listm.get(select_id).getInfo().get(arg2).getNameid();

                pageNumber = 1;
                clearlist();
                // 调用接口数据，重新渲染客户列表
                swipeList.stopLoadMore();
                swipeList.stopRefresh();
                Loading.showDialogForLoading(root, "正在加载...", false, true, 60000);
                getCustomerList("" + setSelect, itemid1, itemid2, "" + pageNumber, "" + pageSize, 1);

            }
        });
    }

    /**
     * <p>
     * <b>Title：</b> 清理列表数据
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月21日 下午3:10:54
     */
    private void clearlist() {
        getcustomer = new GetCustomerList();
        if (adapter == null) {
            adapter = new CustomerAdapter(root, null);
            swipeList.setAdapter(adapter);
        } else {
            adapter.SetDate(null);
        }
    }

    /**
     * <p>
     * <b>Title：</b> 指派
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param consultantList
     * @author tangxin
     * @date 2016年12月21日 下午3:11:09
     */
    public void SetzpPopu(final ArrayList<ConsultantList> consultantList) {
        viewZp = LayoutInflater.from(root).inflate(R.layout.popu_zp, null);
        poPuZp = new PopupWindow(viewZp, android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT,
                android.support.v4.view.ViewPager.LayoutParams.FILL_PARENT);
        poPuZp.setFocusable(true);
        poPuZp.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        poPuZp.showAtLocation(viewZp, Gravity.BOTTOM, 0, 0);
        poPuZp.showAsDropDown(viewZp, 0, 0);
        poPuZp.setFocusable(true);
        poPuZp.setOutsideTouchable(true);
        viewZp.setFocusable(true);
        viewZp.setFocusableInTouchMode(true);

        viewZp.setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    poPuZp.dismiss();
                    EmmApplication.setLog(root);
                }
                return false;
            }
        });

        viewZp.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                poPuZp.dismiss();
                EmmApplication.setLog(root);
            }
        });

        PickerView select_pick = (PickerView) viewZp.findViewById(R.id.select_pick);

        // 初始化数据到需要展示的数据源
        ArrayList<String> list = new ArrayList<String>();
        for (int i = 0; i < consultantList.size(); i++) {
            list.add(consultantList.get(i).getConsultantUserName());
        }
        selectName = list.get(0);

        TextView shuerbtn = (TextView) viewZp.findViewById(R.id.shuerbtn);
        TextView title_select = (TextView) viewZp.findViewById(R.id.title_select);
        ImageView dis_btn = (ImageView) viewZp.findViewById(R.id.dis_btn);

        dis_btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                poPuZp.dismiss();
                EmmApplication.setLog(root);
            }
        });

        RelativeLayout relative_all = (RelativeLayout) viewZp.findViewById(R.id.relative_all);
        // 将数据设置到滑动选择界面
        select_pick.setData(list);
        select_pick.setOnSelectListener(new onSelectListener() {
            @Override
            public void onSelect(String text, int id) {
                selectName = text;
                SelectID = id;
            }
        });

        // 设置默认选择项
        select_pick.setSelected(0);
        shuerbtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // 确定
                poPuZp.dismiss();
                EmmApplication.setLog(root);

                // 执行显示确认按钮消失
                FlyprintInataface.g();

                String consultantUserId = null;
                for (int i = 0; i < consultantList.size(); i++) {
                    if (selectName.equals(consultantList.get(i).getConsultantUserName())) {
                        consultantUserId = consultantList.get(i).getConsultantUserId();
                        break;
                    }
                }
                // 指派接口
                distributionConsultant(consultantUserId, customerList);
            }
        });

        relative_all.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // 点击事件消耗
            }
        });
    }

    /**
     * 客户列表
     */
    GetCustomerList getcustomer;

    /**
     * 页码
     */
    int pageNumber = 1;

    /**
     * 页码条数
     */
    int pageSize = 10;

    boolean IsLoading = true;

    /**
     * 客户列表<br>
     * sort 排序<br>
     * screenType 筛选类型<br>
     * screenValue 筛选类型对应值 <br>
     * pageNumber 页码<br>
     * pageSize 页码大小 opentype 1 刷新 2 加载
     */
    private void getCustomerList(String sort, String screenType, String screenValue, String pageNumberd,
                                 String pageSized, final int opentype) {

        if (!EmmApplication.isErrorCode()) {
            EmmApplication.T();
            return;
        }

        EmmApplication.updateUrl("getCustomerList");
        Map<String, String> map = new HashMap<>();
        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("userId", EmmApplication.getUserId());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        map.put("projectCode", EmmApplication.getProjectCode());
        map.put("type", "");// 此处不传
        map.put("sort", sort);

        if (EmmApplication.isNull(screenType)) {
            map.put("screenType", screenType);
        } else {
            map.put("screenType", "");
        }

        if (EmmApplication.isNull(screenValue)) {
            map.put("screenValue", screenValue);
        } else {
            map.put("screenValue", "");
        }

        map.put("pageNumber", pageNumberd);
        map.put("pageSize", pageSized);

        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v("getCustomerList-->post", EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束error:" + error + "==" + content);
                swipeList.stopRefresh();
                String timed = EmmApplication.dataTime(EmmApplication.geTime(), "yyyy-MM-dd HH:mm");
                swipeList.setRefreshTime(timed);
                swipeList.stopLoadMore();
                EmmApplication.setData("RefreshTime", timed);
                if (null != adapter) {
                    FlyprintInataface.select(adapter.IsSelect());
                    FlyprintInataface.size(adapter.getSize());
                }
            }

            @Override
            public void onFinish() {
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束");
                swipeList.stopRefresh();
                swipeList.stopLoadMore();
                String timed = EmmApplication.dataTime(EmmApplication.geTime(), "yyyy-MM-dd HH:mm");
                swipeList.setRefreshTime(timed);
                EmmApplication.setData("RefreshTime", timed);
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);

                if (content == null) {
                    return;
                }
                Log.v("content", content);

                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");

                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }

                GetCustomerList getcust = JSONObject.parseObject(resData.toString(), GetCustomerList.class);
                if ("1".equals(getcust.getResult())) {
                    Log.v("获取成功", "");
                    if (getcust.getCustomerList() != null) {
                        if (opentype == 1) {// 刷新
                            getcustomer = new GetCustomerList();
                            getcustomer = getcust;
                        } else {// 加载
                            if (getcustomer != null && getcustomer.getCustomerList() != null) {
                                getcustomer.getCustomerList().addAll(getcust.getCustomerList());
                            } else {
                                getcustomer = new GetCustomerList();
                                ArrayList<CustomerList> customerList = new ArrayList<CustomerList>();
                                getcustomer.setCustomerList(customerList);
                                getcustomer.getCustomerList().addAll(getcust.getCustomerList());
                            }
                        }
                        if (getcustomer.getCustomerList().size() < (pageNumber * pageSize)) {// 代表没有更多
                            swipeList.setPullLoadEnable(false);
                            ToastUtils.INSTANCE.showToast("没有更多客户");
                            IsLoading = false;
                            if (opentype != 1) {
                                // EmmApplication.T("没有更多客户");
                            }
                        }
                        if (adapter == null) {
                            adapter = new CustomerAdapter(root, getcustomer.getCustomerList());
                            swipeList.setAdapter(adapter);
                        } else {
                            adapter.SetDate(getcustomer.getCustomerList());
                        }
                    } else {
                        swipeList.setPullLoadEnable(false);
                        if (opentype == 1) {
                            EmmApplication.T2("没有查询到客户");
                        } else {
                            EmmApplication.T2("没有更多客户");
                        }
                        if (pageNumber > 0 && opentype != 1)
                            pageNumber--;
                        ArrayList<CustomerList> arrlist;

                        // 没有数据，就给列表设置空的数据（如果列表不初始化数据进去，下来刷新上拉加载功能也不会同步出现）
                        if (null != getcustomer && null != getcustomer.getCustomerList()) {
                            arrlist = getcustomer.getCustomerList();
                        } else {
                            arrlist = new ArrayList<GetCustomerList.CustomerList>();
                        }

                        if (adapter == null) {
                            adapter = new CustomerAdapter(root, arrlist);
                            swipeList.setAdapter(adapter);
                        } else {
                            adapter.SetDate(arrlist);
                        }
                    }
                    if (adapter != null) {
                        adapter.SetType(2);
                    }
                } else {
                    try {
                        EmmApplication.T(getcust.getErrorMsg().toString());
                        Log.v("获取失败", "errorCode:" + getcust.getErrorCode().toString() + "errorMsg:"
                                + getcust.getErrorMsg().toString());
                    } catch (NullPointerException e) {
                        Log.v("客户列表，错误信息获取空指针异常", "");
                    }
                }
                if (null != adapter && adapter.GetAllSize() > 0) {//列表存在客户的情况
                    //根据当前选中数量更改显示状态
                    FlyprintInataface.select(adapter.IsSelect());
                    FlyprintInataface.size(adapter.getSize());
                }
            }
        });
    }

    /**
     * 查询置业顾问列表数据源
     */
    GetConsultantList getconsultan;

    /**
     * <p>
     * <b>Title：</b> 查询置业顾问列表
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月21日 下午3:18:39
     */
    private void getConsultantList() {
        EmmApplication.updateUrl("getConsultantList");
        Map<String, String> map = new HashMap<String, String>();
        map.put("resourcesCode", "menu_0006_0001");
        map.put("searchType", "0");
        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("userId", EmmApplication.getUserId());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        map.put("projectId", EmmApplication.getProjectID());
        map.put("projectCode", EmmApplication.getProjectCode());
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v(TAG, "getConsultantList-->post" + EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                Log.v(TAG, "请求结束error:" + error + "==" + content);
            }

            @Override
            public void onFinish() {
                Log.v(TAG, "请求结束");
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }
                Log.v("置业顾问content", content);
                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }

                getconsultan = JSONObject.parseObject(resData.toString(), GetConsultantList.class);
                if ("1".equals(getconsultan.getResult())) {
                    Log.v("获取成功", "");
                } else {
                    EmmApplication.T(getconsultan.getErrorMsg().toString());
                    try {
                        Log.v("获取失败", "errorCode:" + getconsultan.getErrorCode().toString() + "errorMsg:"
                                + getconsultan.getErrorMsg().toString());
                    } catch (NullPointerException e) {
                        Log.v("查询置业顾问", "错误信息获取空指针异常");
                    }
                }
            }
        });
    }

    /**
     * 分配置业顾问接口
     */
    DistributionConsultant distribution;

    /**
     * <p>
     * <b>Title：</b> 分配置业顾问接口
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param consultantUserId 置业顾问ID
     * @param customerList
     * @author tangxin
     * @date 2016年12月8日 上午11:01:54
     */
    private void distributionConsultant(String consultantUserId, ArrayList<CustomerListinfo> customerList) {
        EmmApplication.updateUrl("distributionConsultant");
        Map<String, Object> map = new HashMap<String, Object>();

        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("userId", EmmApplication.getUserId());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        map.put("projectCode", EmmApplication.getProjectCode());
        map.put("consultantUserId", consultantUserId);
        map.put("customerList", customerList);
        map.put("projectId", EmmApplication.getProjectID());

        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v(TAG, "distributionConsultant-->post" + EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束error:" + error + "==" + content);
            }

            @Override
            public void onFinish() {
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束");
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                Loading.showDialogForLoading(root, "正在加载...", false, true, 60000);
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }
                Log.v("置业顾问content", content);
                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }

                distribution = JSONObject.parseObject(resData.toString(), DistributionConsultant.class);
                if ("1".equals(distribution.getResult())) {
                    Log.v("获取成功", "");
                    PopuContent.poPu(root, "分配成功", false, 0);

                } else {

                    // 弹出提示框提示错误原因
                    PopuContent.poPu(root, distribution.getErrorMsg().toString(), false, 0);

                    try {
                        Log.v("获取失败", "errorCode:" + distribution.getErrorCode().toString() + "errorMsg:"
                                + distribution.getErrorMsg().toString());
                    } catch (NullPointerException e) {
                        Log.v("distribution", "错误信息获取空指针异常");
                    }
                }
            }
        });
    }

    public class CustomerListinfo {
        private String customerId;// 被分配客户

        public String getCustomerId() {
            return customerId;
        }

        public void setCustomerId(String customerId) {
            this.customerId = customerId;
        }
    }

    ArrayList<RqBusNumList> FirstContactMode;

    /**
     * 字典数据源
     */
    GetDictionaryList getdiction;

    /**
     * <p>
     * <b>Title：</b> 查询字典列表接口
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月21日 下午3:19:15
     */
    private void getDictionaryList() {
        EmmApplication.updateUrl("getDictionaryList");
        Map<String, String> map = new HashMap<String, String>();
        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("projectId", EmmApplication.getProjectID());
        map.put("token", EmmApplication.getToken());
        map.put("userId", EmmApplication.getUserId());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        map.put("busNumType", "contactWay");
        map.put("busNum", "01");
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v(TAG, "getDictionaryList-->post" + EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                Log.v(TAG, "请求结束error:" + error + "==" + content);
            }

            @Override
            public void onFinish() {
                Log.v(TAG, "请求结束");
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }
                Log.v(TAG, "content==:" + content);
                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }
                getdiction = JSONObject.parseObject(resData.toString(), GetDictionaryList.class);
                if ("1".equals(getdiction.getResult())) {
                    FirstContactMode = getdiction.getRqBusNumList();
                } else {
                    EmmApplication.T(getdiction.getErrorMsg().toString());
                    Log.v("获取失败", "errorCode:" + getdiction.getErrorCode().toString() + "errorMsg:"
                            + getdiction.getErrorMsg().toString());
                }
            }
        });
    }

}
